<template>
  <div class="app-container">
    <!--工具栏-->
    <crudOperation :permission="permission" />
    <div class="head-container">
      <div v-if="!crud.props.searchToggle">
<!--        <el-form size="small" label-width="70px">-->
<!--          <el-row :gutter="10">-->
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <el-form-item label="客户名称">-->
<!--                <el-input></el-input>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <el-form-item label="销售部门">-->
<!--                <el-input></el-input>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <el-form-item label="销售人员">-->
<!--                <el-input></el-input>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <el-form-item label="客户分类">-->
<!--                <el-input></el-input>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <el-form-item label="客户区域">-->
<!--                <el-input></el-input>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <rrOperation :crud="crud"/>-->
<!--            </el-col>-->
<!--          </el-row>-->
<!--        </el-form>-->
      </div>
      <el-dialog v-dialog-drag style="width: 80vm" title="搜索"   close-on-click-modal :visible.sync="crud.props.searchToggle"
        width="70%">
        <el-form size="small" class="formClass" label-width="85px" >
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" >
              <el-form-item label="业务日期">
                <div class="flex flex-row">
                  <el-date-picker
                    v-model="query.startBusDate"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="开始日期"
                  />
                  <el-date-picker
                    v-model="query.endBusDate"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="结束日期"
                  />
                </div>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" >
              <el-form-item label="审核日期">
                <div class="flex flex-row">
                  <el-date-picker
                    v-model="query.auditStartTime"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="开始日期"
                  />
                  <el-date-picker
                    v-model="query.auditEndTime"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="结束日期"
                  />
                </div>
              </el-form-item>
            </el-col>
<!--            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" >-->
<!--              <el-form-item label="验收日期">-->
<!--                <div class="flex flex-row">-->
<!--                  <el-date-picker-->
<!--                    v-model="query.acceptStartDate"-->
<!--                    align="right"-->
<!--                    unlink-panels-->
<!--                    class="fl1"-->
<!--                    format="yyyy - MM - dd "-->
<!--                    value-format="yyyy-MM-dd"-->
<!--                    default-value-->
<!--                    range-separator=""-->
<!--                    placeholder="开始日期"-->
<!--                  />-->
<!--                  <el-date-picker-->
<!--                    v-model="query.acceptEndDate"-->
<!--                    align="right"-->
<!--                    unlink-panels-->
<!--                    class="fl1"-->
<!--                    format="yyyy - MM - dd "-->
<!--                    value-format="yyyy-MM-dd"-->
<!--                    default-value-->
<!--                    range-separator=""-->
<!--                    placeholder="结束日期"-->
<!--                  />-->
<!--                </div>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <el-form-item label="商品">-->
<!--                <table-select-->
<!--                  :tableColumns="[{prop:'goodsCode',label:'商品编码'},{prop:'goodsName',label:'商品名称'}]"-->
<!--                  labelKey="goodsName"-->
<!--                  valueKey="goodsId"-->
<!--                  :value.sync="query.goodsIds"-->
<!--                  placeholder="请选择商品"-->
<!--                  url="/api/dropDown/basGoodsListForAdd"-->
<!--                ></table-select>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <el-form-item label="品牌">-->
<!--                <zSelect multiple :value.sync="goodsBrandIds"  url="/api/dropDown/basGoodsBrandList"-->
<!--                         style="width:  100%;"/>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <el-form-item label="二级代理">-->
<!--                <zSelect multiple :value.sync="sCustomerIds"  url="/api/dropDown/basCustomerList" :params="{type:3}"-->
<!--                         style="width:  100%;"/>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--              <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--                <el-form-item label="销售区域">-->
<!--                  <treeselect-->
<!--                    v-model="customerAreaIds"-->
<!--                    :options="areaData"-->
<!--                    placeholder="销售区域"-->
<!--                    style="width: 100%"-->
<!--                    :normalizer="normalizer"-->
<!--                    multiple-->
<!--                    @input="getArea"-->
<!--                  />-->
<!--                </el-form-item>-->
<!--              </el-col>-->
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <el-form-item label="客户">-->
<!--                <zSelect multiple :value.sync="customerIds"  url="api/dropDown/basCustomerList"-->
<!--                         style="width:  100%;"/>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <el-form-item label="客户分类">-->
<!--                <treeselect-->
<!--                  v-model="customerTypeIds"-->
<!--                  :options="customerTypeList"-->
<!--                  placeholder="客户分类"-->
<!--                  style="width: 100%"-->
<!--                  :normalizer="normalizer"-->
<!--                  multiple-->
<!--                  @select="onCustomerNode"-->
<!--                />-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <el-form-item label="车辆">-->
<!--                <zSelect multiple :value.sync="query.carIds"   url="api/dropDown/basCarList"    style="width: 100%;"/>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
              <el-form-item label="司机">
                <table-select
                  :tableColumns="
                  [
                  {prop:'name',label:'司机名称'},
                  ]
              "
                  labelKey="name"
                  valueKey="id"
                  width="400"
                  :params="{businessAttr:'5'}"
                  :value.sync="query.driverIds"
                  placeholder="请选择司机"
                  url="/api/dropDown/sysUserList"
                ></table-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row class="flex fow-reverse" >
            <el-button class="filter-item"  size="mini" type="primary" @click="queryReport">搜索</el-button>
            <el-button class="filter-item" plain   size="mini" type="primary"
                       @click="resetQuery" >重置</el-button>
          </el-row>
        </el-form>
      </el-dialog>
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="业务日期">
            <el-input v-model="form.busDate" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="单据类型(1:销售订单 2:销售退货 3:回瓶回箱)">
            <el-input v-model="form.orderType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="单据id">
            <el-input v-model="form.orderId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="单据编码">
            <el-input v-model="form.orderCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="单据名称">
            <el-input v-model="form.orderName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="单据状态(SAVE:保存 PASS:审核 CLOSE:关闭)">
            <el-input v-model="form.orderStatus" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="客户id">
            <el-input v-model="form.customerId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="客户编码">
            <el-input v-model="form.customerCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="客户名称">
            <el-input v-model="form.customerName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属总店id">
            <el-input v-model="form.pCustomerId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属总店编码">
            <el-input v-model="form.pCustomerCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属总店名称">
            <el-input v-model="form.pCustomerName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属商场id">
            <el-input v-model="form.mCustomerId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属商场编码">
            <el-input v-model="form.mCustomerCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属商场名称">
            <el-input v-model="form.mCustomerName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="部门id">
            <el-input v-model="form.deptId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="部门编码">
            <el-input v-model="form.deptCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="部门名称">
            <el-input v-model="form.deptName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="人员id">
            <el-input v-model="form.userId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="人员编码">
            <el-input v-model="form.userCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="人员名称">
            <el-input v-model="form.userName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="仓库id">
            <el-input v-model="form.warehouseId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="仓库编码">
            <el-input v-model="form.warehouseCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="仓库名称">
            <el-input v-model="form.warehouseName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="单据备注">
            <el-input v-model="form.orderRemark" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品id" prop="goodsId">
            <el-input v-model="form.goodsId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品编码">
            <el-input v-model="form.goodsCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品名称">
            <el-input v-model="form.goodsName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="包装类型(1:纸箱 2:塑箱 3:其他)">
            <el-input v-model="form.packageType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="条形码">
            <el-input v-model="form.barcode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱装条形码">
            <el-input v-model="form.boxBarcode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="助记符">
            <el-input v-model="form.helpSign" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="规格型号">
            <el-input v-model="form.model" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品品牌id">
            <el-input v-model="form.goodsBrandId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品品牌编码">
            <el-input v-model="form.goodsBrandCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品品牌名称">
            <el-input v-model="form.goodsBrandName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品分类id">
            <el-input v-model="form.goodsTypeId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品分类编码">
            <el-input v-model="form.goodsTypeCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品分类名称">
            <el-input v-model="form.goodsTypeName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品类型id">
            <el-input v-model="form.goodsTagId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品类型编码">
            <el-input v-model="form.goodsTagCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品类型名称">
            <el-input v-model="form.goodsTagName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱单位id">
            <el-input v-model="form.boxUnitId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱单位编码">
            <el-input v-model="form.boxUnitCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱单位名称">
            <el-input v-model="form.boxUnitName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱数单位计量数">
            <el-input v-model="form.boxUnitCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱单位数量">
            <el-input v-model="form.boxNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主单位id">
            <el-input v-model="form.mainUnitId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主单位编码">
            <el-input v-model="form.mainUnitCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主单位名称">
            <el-input v-model="form.mainUnitName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主单位计量数">
            <el-input v-model="form.mainUnitCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主单位数量">
            <el-input v-model="form.mainNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="数量">
            <el-input v-model="form.goodsCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱数">
            <el-input v-model="form.boxCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="含税单价">
            <el-input v-model="form.taxPrice" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="未税单价">
            <el-input v-model="form.noTaxPrice" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="含税箱价">
            <el-input v-model="form.taxBoxPrice" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="未税箱价">
            <el-input v-model="form.noTaxBoxPrice" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="含税金额">
            <el-input v-model="form.taxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="未税金额">
            <el-input v-model="form.noTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="税额">
            <el-input v-model="form.tax" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收数量">
            <el-input v-model="form.acceptGoodsCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收箱数">
            <el-input v-model="form.acceptBoxCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收箱单位数量">
            <el-input v-model="form.acceptBoxNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收主单位数量">
            <el-input v-model="form.acceptMainNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收含税金额">
            <el-input v-model="form.acceptTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收未税金额">
            <el-input v-model="form.acceptNoTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收税额">
            <el-input v-model="form.acceptTax" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="已核销金额">
            <el-input v-model="form.cancelAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="未核销金额">
            <el-input v-model="form.unCancelAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品备注">
            <el-input v-model="form.goodsRemark" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="添加人id">
            <el-input v-model="form.createUserId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="添加人编码">
            <el-input v-model="form.createUserCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="添加人名称">
            <el-input v-model="form.createUserName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="添加时间">
            <el-input v-model="form.createTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="审核人id">
            <el-input v-model="form.auditUserId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="审核人编码">
            <el-input v-model="form.auditUserCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="审核人名称">
            <el-input v-model="form.auditUserName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="审核时间">
            <el-input v-model="form.auditTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="关闭人id">
            <el-input v-model="form.closeUserId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="关闭人编码">
            <el-input v-model="form.closeUserCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="关闭人名称">
            <el-input v-model="form.closeUserName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="关闭时间">
            <el-input v-model="form.closeTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收日期">
            <el-input v-model="form.acceptDate" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收人员id">
            <el-input v-model="form.acceptUserId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收人员编码">
            <el-input v-model="form.acceptUserCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收人员名称">
            <el-input v-model="form.acceptUserName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="核销日期">
            <el-input v-model="form.cancelDate" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="核销人员id">
            <el-input v-model="form.cancelUserId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="核销人员编码">
            <el-input v-model="form.cancelUserCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="核销人员名称">
            <el-input v-model="form.cancelUserName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="id">
            <el-input v-model="form.id" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <vue-context-menu :contextMenuData="contextMenuData"
                        @tableConfig="tableConfig"
                        @deletedata="deletedata"></vue-context-menu>
      <!-- 表格配置 -->
      <el-dialog title="表格配置"
                 :visible.sync="tableConfigShow"
                 width="60%">
        <j-table-column-config :columns.sync="crud.header"  @tabSave="tabSave" @pit="pit" />
      </el-dialog>

      <!--表格渲染-->
      <el-table ref="table" border :data="crud.data" size="small"
                style="width: 100%;" v-if="isShowTable"
                @header-dragend="changeColWidth"
                show-summary
                height="700"
                :summary-method="crud.sumRow"
                @row-click="crud.selectRow"
                :row-style="crud.rowClass"
                :row-class-name="crud.tableRowClassName"
                @contextmenu.native="showMenu"
                @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column type="index" width="55" label="序号"/>
<!--        <自定义列>-->
<!--        <el-table-column-->
<!--          v-if="item.visible"-->
<!--          v-for="(item, index) in crud.header"-->
<!--          :key="`col_${index}`"-->
<!--          :prop="item.prop"-->
<!--          :label="columnLabel(item)"-->
<!--          :width="item.width + 'px'"-->
<!--          :data-porp='item.prop'-->
<!--          @contextmenu.native="showMenu"-->
<!--          @header-dragend="changeColWidth"-->
<!--        >-->
<!--          &lt;!&ndash; 自定义渲染模版 &ndash;&gt;-->
<!--          <template slot-scope="scope">-->
<!--            &lt;!&ndash; 当列key为 sort 时，渲染一个手柄icon &ndash;&gt;-->
<!--            <template>-->
<!--              <span v-if="item.type == 1" >-->
<!--                <span v-if="item.prop === 'orderCode'" class="codeJump" @click="jump(scope.row)">-->
<!--                  {{scope.row[`${item.prop}`]}}-->
<!--                </span>-->
<!--                <span v-else-if="item.prop === 'sendOrderCode'">-->
<!--                  <span v-for="(item,index) in getBillCode(scope.row[`${item.prop}`])" @click="jumpSend(scope.row[`sendOrderIds`],index,'/ware/wareSalesInvoiceDetail/',scope.row)" class="codeJump">-->
<!--                    {{ item }}-->
<!--                  </span>-->
<!--                </span>-->
<!--                <span v-else-if="item.prop === 'loadCode'">-->
<!--                  <span v-for="(item,index) in getBillCode(scope.row[`${item.prop}`])" @click="jumpSend(scope.row[`loadIds`],index,'/logistics/logisticsLoadDetail/')" class="codeJump">-->
<!--                    {{ item }}-->
<!--                  </span>-->
<!--                </span>-->
<!--                <span v-else>{{scope.row[`${item.prop}`]}}</span>-->
<!--              </span>-->
<!--              <span v-else-if="item.type == 2" >{{ parseTime(scope.row[`${item.prop}`])}}</span>-->
<!--              <span v-else-if="item.type == 3" >{{ getDict(`this.dict.label.${item.dictionary}["${scope.row[item.prop]}"]`) }}</span>-->
<!--            </template>-->
<!--          </template>-->
<!--        </el-table-column>-->
        <el-table-column v-if="columns.visible('userName')" prop="userName" label="配送员" />
        <el-table-column v-if="columns.visible('loadBoxCount')" prop="loadBoxCount" label="发货箱数" />
        <el-table-column v-if="columns.visible('salesReturnBoxCount')" prop="salesReturnBoxCount" label="退货箱数" />
        <el-table-column v-if="columns.visible('returnBottleBoxCount')" prop="returnBottleBoxCount" label="回箱箱数" />
        <el-table-column v-if="columns.visible('returnBoxRate')" prop="returnBoxRate" label="回箱率" />
        <el-table-column v-if="columns.visible('loadInvoiceCount')" prop="loadInvoiceCount" label="配送单数" />
        <el-table-column v-if="columns.visible('salesInvoiceCount')" prop="salesInvoiceCount" label="送货单数" />
      </el-table>
      <!--分页组件-->

      <pagination/>
    </div>
  </div>
</template>

<script>
import crudReportDriverLoad from '@/api/erp/reportDriverLoad'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import {getBasGoodsTypeTree} from "@/api/erp/basGoodsType";
import Treeselect from '@riophae/vue-treeselect'
import {get} from '@/api/erp/reportDriverLoad'
import { publicListKey } from "@/utils/key";
import {getHeaderProperties} from "@/api/erp/headerProperties";
import {tablemixins} from "@/mixins/tablemixins";
import  jTableColumnConfig  from "@/components/jTableColumnConfig/jTableColumnConfig";
import {getAreaTree} from "@/api/erp/basCustomerArea";
import {getCustomerTypeTree} from "@/api/erp/basCustomerType";
import tableSelect from '@/components/tableSelect/tableSelect'


// crud交由presenter持有
const defaultCrud = CRUD({ title: '司机配送情况统计',
  optShow: {
    add: false,
    edit: false,
    del: false,
    download: true,
    leadingIn: false,
    enable: false,
    disable: false,
    pass: false,
    reject: false,
    invalid: false,
    recover: false,
    downloadDetail: false,
    print: false,
    printDetail: false
  },
queryOnPresenterCreated:false,
  url: 'api/reportDriverLoad', sort: '',
  crudMethod: { ...crudReportDriverLoad }})
const defaultForm = { busDate: null, orderType: null, orderId: null, orderCode: null, orderName: null, orderStatus: null, customerId: null, customerCode: null, customerName: null, pCustomerId: null, pCustomerCode: null, pCustomerName: null, mCustomerId: null, mCustomerCode: null, mCustomerName: null, deptId: null, deptCode: null, deptName: null, userId: null, userCode: null, userName: null, warehouseId: null, warehouseCode: null, warehouseName: null, orderRemark: null, goodsId: null, goodsCode: null, goodsName: null, packageType: null, barcode: null, boxBarcode: null, helpSign: null, model: null, goodsBrandId: null, goodsBrandCode: null, goodsBrandName: null, goodsTypeId: null, goodsTypeCode: null, goodsTypeName: null, goodsTagId: null, goodsTagCode: null, goodsTagName: null, boxUnitId: null, boxUnitCode: null, boxUnitName: null, boxUnitCount: null, boxNum: null, mainUnitId: null, mainUnitCode: null, mainUnitName: null, mainUnitCount: null, mainNum: null, goodsCount: null, boxCount: null, taxPrice: null, noTaxPrice: null, taxBoxPrice: null, noTaxBoxPrice: null, taxAmount: null, noTaxAmount: null, tax: null, acceptGoodsCount: null, acceptBoxCount: null, acceptBoxNum: null, acceptMainNum: null, acceptTaxAmount: null, acceptNoTaxAmount: null, acceptTax: null, cancelAmount: null, unCancelAmount: null, goodsRemark: null, createUserId: null, createUserCode: null, createUserName: null, createTime: null, auditUserId: null, auditUserCode: null, auditUserName: null, auditTime: null, closeUserId: null, closeUserCode: null, closeUserName: null, closeTime: null, acceptDate: null, acceptUserId: null, acceptUserCode: null, acceptUserName: null, cancelDate: null, cancelUserId: null, cancelUserCode: null, cancelUserName: null, id: null }
export default {
  name: 'ReportDriverLoad',
  components: { pagination, crudOperation, rrOperation, udOperation,Treeselect,jTableColumnConfig, tableSelect },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud(),publicListKey,tablemixins],
  dicts:['t_report_Driver_flow_order_type','common_order_status','common_cancel_status','common_yes_or_no','t_bas_goods_package_type'],
  mounted(){
    const date  = new Date().toISOString().split('T')[0]
    this.dataExtent[0] = date
    this.dataExtent[1] = date
    this.crud.props.searchToggle =false
    // this.queryReport()
  },
  created() {
    // getBasGoodsTypeTree({size:999}).then(res=>{
    //   this.areaList = res.data
    // })
    getCustomerTypeTree({size:999}).then(res=>{
      this.customerTypeList = res
    })
    this.getAreaTree()
    this.$set(this.query,'startBusDate',new Date().toISOString().split('T')[0])
    this.$set(this.query,'endBusDate',new Date().toISOString().split('T')[0])
  },
  data() {
    return {
      customerTypeIds:[],
      isSend:[],
      fCustomerIds:[],
      pCustomerIds:[],
      mCustomerIds:[],
      customerAreaIds:[],
      total:0,
      areaList:[],
      orderType:[],
      cancelStatus:[],
      orderStatus:[],
      createdataExtent:[],
      dialogVisible:false,
      dataExtent:[],
      dataExtent01:[],
      dataExtent02:[],
      goodsTypeIds:[],
      goodsBrandIds:[],
      warehouseIds:[],
      goodsIds:[],
      driverUserIds:[],
      areaData:[],
      customerIds:[],
      sCustomerIds:[],
      packageType:[],
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      jumpPath:[
        '/sale/salesorderDetail/',
        '/sale/salesorderDetail/',
        '/ware/wareReturnBottleBoxDetail/',
      ],
      goodsTagList:[],
      userIds:[],
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },

      permission: {
        add: ['admin', 'reportDriverLoad:add'],
        edit: ['admin', 'reportDriverLoad:edit'],
        del: ['admin', 'reportDriverLoad:del'],
        import: ['admin', 'reportDriverLoad:import'],
        export: ['admin', 'reportDriverLoad:export'],
        copy: ['admin', 'reportDriverLoad:copy'],
        upload: ['admin', 'reportDriverLoad:upload'],
        download: ['admin', 'reportDriverLoad:download'],
        pass: ['admin', 'reportDriverLoad:pass'],
        reject: ['admin', 'reportDriverLoad:reject'],
        closed: ['admin', 'reportDriverLoad:closed'],
        invalid: ['admin', 'reportDriverLoad:invalid'],
        stop: ['admin', 'reportDriverLoad:stop'],
        recover: ['admin', 'reportDriverLoad:recover'],

      },
      rules: {
        goodsId: [
          { required: true, message: '商品id不能为空', trigger: 'blur' }
        ]
      },
    }
  },
  updated() {
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })
  },
  watch: {
    customerTypeIds(n){
      if (!n.length){
        this.query.customerTypeIds = null
      }
    },
    packageType(n,o){
      if (n.length){
      this.query.packageType = this.packageType.join(',')
    }else{
      this.query.packageType =null
    }
    }
    // goodsTypeIds(n){
    //   if (!n.length){
    //     this.query.goodsTypeIds = null
    //   }
    // },
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },
    getValue(e){
      if (this.dataExtent){
        this.query.startBusDate = this.dataExtent[0]
        this.query.endBusDate = this.dataExtent[1]
      }else {
        this.query.startBusDate = null
        this.query.endBusDate = null
      }
    },
    getValue02(e){
      if (this.createdataExtent) {
        this.query.createStartDate = this.createdataExtent[0]
        this.query.createEndDate = this.createdataExtent[1]
      }else {
        this.query.createStartDate = null
        this.query.createEndDate = null
      }
    },
    getAcceptValue(){
      if (this.dataExtent02) {
      this.query.startAcceptDate = this.dataExtent02[0]
      this.query.endAcceptDate = this.dataExtent02[1]
      } else {
        this.query.startAcceptDate = null
        this.query.endAcceptDate = null
      }
    },
    getAreaTree() {
      getAreaTree({status: 1}).then(res => {
        this.areaData = res
        this.areaList = res
      })
    },
    getSendValue(e){
      if (this.dataExtent01) {
        this.query.sendStartDate = this.dataExtent01[0]
        this.query.sendEndDate = this.dataExtent01[1]
      }else {
        this.query.sendStartDate = null
        this.query.sendEndDate = null
      }
    },
    getTypeChildren(val){
      console.log(val)
    },
    normalizer(node) {
      //去掉children=[]的children属性
      if (node.children == null || node.children.length == 0) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children
      }
    },
    init(){
      this.page = 1
    },
    getBillCode(ids){
      if (ids){
        return ids.split(',')
      }
    },
    onGet(){
      const that =this
      let { page,size } = this.crud.page
      page =  1
      get({...this.query,page,size}).then(res=>{
        that.crud.data = res.data.content
        that.crud.page.total = res.data.totalElements
        console.log(that.total)
      })
    },
    jumpSend(ids,index,path,row){
      const idsList = ids.split(',')
      if (path === '/ware/wareSalesInvoiceDetail/'){
        const typeList = row.sendOrderType.split(',')
        switch (typeList[index]){
          case '2':
            path = '/ware/wareSalesReturnDetail/'
            break
          case '3':
            path = '/ware/wareReturnBottleBoxDetail/'
            break
        }
      }
      this.$router.push({path:`${path}${idsList[index]}`})
    },
    jump(row){
      this.$router.push({path:this.jumpPath[Number(row.orderType)-1]+row.orderId})
    },
    onCustomerNode(node){
      this.query.customerTypeIds = this.getNode(node,this.query.customerTypeIds?this.query.customerTypeIds:'')
    },
    getgoodsType(val){
      let str = ''
      val.forEach(item=>{
        const itemNode = this.getTreeName(this.areaList,item)
        str = this.getNode(itemNode,str)
      })
      this.query.goodsTypeIds = str
      console.log('================')
      console.log(this.query.goodsTypeIds)
    },
    getArea(val){
      let str = ''
      console.log(this.areaList)
      val.forEach(item=>{
        const itemNode = this.getTreeName(this.areaList,item)
        console.log('-----------------------')
        console.log(itemNode)
        str = this.getNode(itemNode,str)
      })
      this.query.customerAreaIds = str
      console.log('================')
      console.log(this.query.customerAreaIds)
    },
    getTreeName(treeList,id){
      let _this=this
      for (let i = 0; i < treeList.length; i++) {
        let treeItem=treeList[i]
        if(treeItem.id===
          id){
          return treeItem
        }else{
          if(treeItem.children && treeItem.children.length>0){
            let res=_this.getTreeName(treeItem.children,id)
            if(res){
              return res
            }
          }
        }
      }
    },
    delgoodsType(node){
      const list = this.getNode(node,'').split(',')
      const oldList = this.query.goodsTypeIds.split(',')
      for(let i =oldList.length;i>0;i--){
        console.log(list)
        console.log(oldList[i])
        console.log(list.includes(oldList[i]))
        if (list.includes(oldList[i])){
          oldList.splice(i,1)
        }
      }
      this.query.goodsTypeIds = oldList.join(',')
      console.log(this.query.goodsTypeIds)
    },
    delareaType(node){
      const list = this.getNode(node,'').split(',')
      const oldList = this.query.customerAreaIds.split(',')
      for(let i =oldList.length;i>0;i--){
        console.log(list)
        console.log(oldList[i])
        console.log(list.includes(oldList[i]))
        if (list.includes(oldList[i])){
          oldList.splice(i,1)
        }
      }
      this.query.customerAreaIds = oldList.join(',')
      console.log(this.query.customerAreaIds)
    },
    getNode(node,str){
      if (node.children){
        for (let i =0;i<node.children.length;i++){
          str = this.getNode(node.children[i],str)
        }
      }
      return str+=node.id+ ','
    },
    resetQuery(){
      // this.query = {
      //   customerIds:null,
      //   customerTypeIds:null,
      //   customerKeyword:'',
      //   endDate:null,
      //   orderCode:null,
      //   orderType: null,
      //   goodsKeyword:'',
      //   goodsTypeIds:null,
      //   goodsBrandIds:null,
      //   orderRemark:'',
      //   goodsRemark: '',
      //   orderStatus: null,
      //   warehouseIds: null,
      //   startDate:null,
      //   pCustomerIds:'',
      //   mCustomerIds:'',
      //   goodsIds:'',
      //   sendStartDate:null,
      //   sendEndDate:null,
      //   cancelStatus:null,
      //   isSend:null,
      //   driverUserIds:'',
      //   goodsTagIds: null,
      //   fCustomerIds: null,
      //   page:1,
      //   size:10,
      //
      //   sort:'auditTime,desc'
      // }

      this.goodsTypeIds = []
      this.orderType  = []
      this.cancelStatus=[]
      this.goodsBrandIds = []
      this.orderStatus  = []
      this.warehouseIds = []
      this.pCustomerIds = []
      this.mCustomerIds = []
      this.goodsIds = []
      this.isSend = []
      this.driverUserIds = []
      this.customerAreaIds = []
      this.userIds=[]
      this.dataExtent = []
      this.packageType = []
      this.dataExtent01 = []
      this.driverUserids =[]
      this.goodsTagList = []
      this.fCustomerIds = []
      this.customerIds = []
      this.customerTypeIds=[]
      this.dataExtent02=[]
      this.sCustomerIds=[]
      this.createdataExtent = []
      this.crud.resetQuery()
    },
    checkArea(data, node) {
      this.query.customerAreaId = data.id
      // this.$refs.areaTree.setCheckedNodes([node])
      this.crud.toQuery()
    },
    queryReport(){
      this.init()
      this.crud.toQuery()
      this.crud.props.searchToggle = false
    }
  }
}
</script>

<style lang="scss" scoped>
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
  .flex{
    display: flex;
  }
  .fow-reverse{
    flex-direction: row-reverse;
  }
  .codeJump{
    background-image:-webkit-linear-gradient(top,yellow,#ff00fb);
    -webkit-background-clip:text;
    -webkit-text-fill-color:transparent;
    cursor: pointer;
  }
</style>
